<template>
  <div class="elm-edit">
    <elm-page-bb>
      <el-form ref="model" :model="model" size="small" label-width="120px">
        <elm-row>
          <el-form-item label="物资编码" prop="sys_code_key">
            <el-input v-model="model.sys_code_key" disabled placeholder="自动生成无需填写"></el-input>
          </el-form-item>
          <el-form-item label="物资名称" prop="name" :rules="[{ required: true, message: '必须填写'}]">
            <el-input v-model="model.name"></el-input>
          </el-form-item>
        </elm-row>
        <elm-row>
          <el-form-item label="物资类别" prop="type">
            <elm-goods-type v-model="model.type"></elm-goods-type>
          </el-form-item>
          <el-form-item label="规格/型号" prop="specification">
            <el-input v-model="model.specification"></el-input>
          </el-form-item>
        </elm-row>
        <elm-row>
          <el-form-item label="单位" prop="unit" >
            <el-input v-model="model.unit"></el-input>
          </el-form-item>
          <el-form-item label="价格" prop="price" :rules="[{trigger: 'blur' ,validator: validateNumber}]">
            <el-input v-model="model.price">
              <template slot="append"><div style="width: 25px;text-align: center;">元</div></template>
            </el-input>
          </el-form-item>
        </elm-row>
        <el-form-item label="厂家" prop="manufacturer">
          <el-input v-model="model.manufacturer" type="textarea" :rows="2"></el-input>
        </el-form-item>
        <el-form-item label="备注" prop="notes">
          <el-input v-model="model.notes" type="textarea" :rows="2"></el-input>
        </el-form-item>
      </el-form>
      <template #bottom>
        <el-button type="success" size="small" @click="submit">立即保存</el-button>
        <el-button size="small" @click="close">取消</el-button>
      </template>
    </elm-page-bb>
  </div>
</template>

<script>
export default {
  extends: elmVueBase,
  data() {
    return {
      model: {id: elm.newGuid(),},
    }
  },
  async created() {
  },
  destroyed() {
    this.request.callVue.tablebinding();
  },
  methods: {

    async submit() {
      await this.$refs["model"].validate();
      var res = await elm.post('/business/wms/goods/Upsert', this.model);
      if (res == true) {
        this.v('保存成功。')
        this.close();
        this.request.callVue.tablebinding();
      }
      else {
        this.error('保存失败，请稍后尝试。');
      }
    },
  }
}
</script>